import profile
import script.LuaPreprocessor as LuaPreprocessor
import script.LuaMerger as LuaMerger
import helpers.FileHelper as FileHelper
import helpers.MiscHelper as MiscHelper
import checkers.ASCIIChecker as ASCIIChecker
import checkers.ImageChecker as ImageChecker
import checkers.VersionChecker as VersionChecker
from package.PackageInterface import PackageInterface
from package.AmazingFeature import AmazingFeature


class InfoSticker(PackageInterface):

    def __init__(self, root_path, conf):
        PackageInterface.__init__(self, root_path, conf)
        self.feature = AmazingFeature(self.path)


    def setup(self, opts):
        for k in opts:
            v = opts[k]
            if k == "check-ascii":
                ASCIIChecker.check(self.path)
            elif k == "check-image":
                ImageChecker.check(self.path)
            # elif k == "check-version":
            #     VersionChecker.check(self.conf, profile.info_sticker_min_version)
            elif k in ("D", "define"):
                LuaPreprocessor.preprocess(MiscHelper.parse_macros(v), self.path)
            elif k in ("m", "merge"):
                self.merge()
            elif k in ("b", "binary"):
                self.feature.convert(True)
            elif k in ("t", "text"):
                self.feature.convert(False)
            elif k in ("h", "rehash"):
                self.rehash(profile.info_sticker_min_version)
            elif k in ("s", "sign"):
                self.sign()


    def merge(self):
        root_path = FileHelper.solve_path(self.path, "lua", "src")
        LuaMerger.merge(root_path, "TextEntry", FileHelper.solve_path(self.path, "lua", "TextAnim.lua"))
        LuaMerger.merge(root_path, "TextCtrlEntry", FileHelper.solve_path(self.path, "lua", "TextAnim.lua"))
        LuaMerger.merge(root_path, "SubtitleEntry", FileHelper.solve_path(self.path, "lua", "TextAnim.lua"))


